package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.manager.controller.dto.MemberDynamicDTO;
import com.quwan.manager.service.ManagerMemberDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author laozhang
 * @date 2021/11/2 10:55
 */
@Api(tags = "后台动态管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/dynamic")
public class ManagerMemberDynamicController  extends BaseController {

    private final ManagerMemberDynamicService managerMemberDynamicService;
    @ApiOperation(value = "动态管理列表分页",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("managerDynamicListPage")
    public ApiResult<PageResult<MemberDynamicDTO>> managerDynamicListPage(@RequestParam(defaultValue = "1") int page,
                                                                          @RequestParam(defaultValue = "10") int size,
                                                                          @ApiParam(value = "会员id") @RequestParam(required = false) String mId,
                                                                          @ApiParam(value = "会员名称") @RequestParam(required = false) String name,
                                                                          @ApiParam(value = "开始时间 yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                                                          @ApiParam(value = "结束时间 yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        if(endTime != null && !endTime.equals("")){
            endTime = endTime+" 23:59:59";
        }
        PageResult<MemberDynamicDTO> res = managerMemberDynamicService.getManagerMemberDynamicList(page,size,mId,name,beginTime,endTime);
        return ApiResult.success(res);
    }

    @PostMapping("delDynamic")
    @ApiOperation("删除动态管理")
    public ApiResult delDynamic(@ApiParam(value = "id主键") @RequestParam(value="id") String id){
        boolean success = managerMemberDynamicService.delDynamic(id);
        if (success)
            return ApiResult.successMsg();
        else
            return ApiResult.failed();
    }
}
